package cn.test.shard.rule;

import java.util.Collection;

import com.dangdang.ddframe.rdb.sharding.api.ShardingValue;
import com.dangdang.ddframe.rdb.sharding.api.strategy.table.SingleKeyTableShardingAlgorithm;

/**
 * @author Han
 */
public class TableShardingAlgorithm implements SingleKeyTableShardingAlgorithm<Integer> {

	@Override
	public String doEqualSharding(Collection<String> availableTargetNames, ShardingValue<Integer> shardingValue) {
		for(String table : availableTargetNames){
			if(table.endsWith(shardingValue.getValue() % 2 + "")){
				return table;
			}
		}
		throw new IllegalArgumentException();
	}

	@Override
	public Collection<String> doInSharding(Collection<String> availableTargetNames, ShardingValue<Integer> shardingValue) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Collection<String> doBetweenSharding(Collection<String> availableTargetNames, ShardingValue<Integer> shardingValue) {
		// TODO Auto-generated method stub
		return null;
	}

}
